package com.jprocms.module.cms.controller.admin.tplinclude;

import com.jpro.framework.common.pojo.CommonResult;
import com.jprocms.module.cms.controller.admin.tplinclude.vo.TplIncludeSaveReqVO;
import com.jprocms.module.cms.service.tplinclude.TplIncludeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.jpro.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 模板包含页面")
@RestController
@RequestMapping("/cms/tpl-include")
@Validated
public class TplIncludeController {

    @Resource
    private TplIncludeService tplIncludeService;

    @PostMapping("/create")
    @Operation(summary = "创建模板包含页面")
    @PreAuthorize("@ss.hasPermission('cms:tpl-include:create')")
    public CommonResult<Long> createTplInclude(@Valid @RequestBody TplIncludeSaveReqVO createReqVO) {
        return success(tplIncludeService.createTplInclude(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新模板包含页面")
    @PreAuthorize("@ss.hasPermission('cms:tpl-include:update')")
    public CommonResult<Boolean> updateTplInclude(@Valid @RequestBody TplIncludeSaveReqVO updateReqVO) {
        tplIncludeService.updateTplInclude(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除模板包含页面")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('cms:tpl-include:delete')")
    public CommonResult<Boolean> deleteTplInclude(@RequestParam("id") Long id) {
        tplIncludeService.deleteTplInclude(id);
        return success(true);
    }

}